#include "stdafx.h"


    namespace network
    {

		PacketManager* PacketManager::m_singleton = NULL;

		PacketManager::PacketManager()
        {
			registerPacket( (boost::uint16_t)Event::EVENT_CANCEL,new packet::CancelOperation());
		}
	
        PacketManager::~PacketManager()
        {
            for (std::map< boost::uint16_t, packet::BasicPacket* >::iterator it_map = m_mPacket.begin(); it_map != m_mPacket.end(); it_map++)
            {
				if( it_map->second != NULL )
					delete it_map->second;
				it_map->second = NULL;
            }
            m_mPacket.clear();

        }

		bool PacketManager::checkPacketId( buffer::BasicBuffer* _packet )
		{
			std::map< boost::uint16_t, packet::BasicPacket*>::iterator it_packet = m_mPacket.find( _packet->getId() );

			if( it_packet != m_mPacket.end() )
				return true;

			return false;
		}

        void PacketManager::registerPacket(boost::uint16_t _opcode, packet::BasicPacket* _packet)
        {
			BOOST_ASSERT( _packet );
            m_mPacket[_opcode] = _packet;
        }

    } //	namespace network
